package com.kob.backend.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 格式校验工具类
 *
 * @Author: CZY
 * @date: 2024/9/1 15:04
 */
public class ValidatorUtil {

    private static final String PHONE_NUMBER_PATTERN = "^(13[0-9]|14[5-9]|15[0-3,5-9]|16[2,5-7]|17[0-3,5-8]|18[0-9]|19[1,8,9])\\d{8}$";

    private static final String EMAIL_PATTERN = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,6}$";

    public static boolean checkPhone(String phoneNumber) {
        Pattern pattern = Pattern.compile(PHONE_NUMBER_PATTERN);
        Matcher matcher = pattern.matcher(phoneNumber);
        return matcher.matches();
    }

    public static boolean checkEmail(String email) {
        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }
}
